package com.okx.bot.service;

import cn.hutool.http.HttpUtil;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.Map;

@Service
public class SendService {
    private Map<String, LocalDateTime> lastTimeMap = new HashMap<>();

    public void wxSend(String instId) {
        LocalDateTime now = LocalDateTime.now();
        if (shouldSend(instId, now)) {
            String url = "https://wxpusher.zjiecode.com/api/send/message/SPT_5lbg3MURtyVsxZQopEVz1YT9wK4c/" + instId;
            HttpUtil.get(url);
            lastTimeMap.put(instId, now);
        }
    }

    public boolean shouldSend(String instId, LocalDateTime now) {
        LocalDateTime lastTime = lastTimeMap.getOrDefault(instId, LocalDateTime.MIN);
        return ChronoUnit.MINUTES.between(lastTime, now) >= 5;
    }
}
